package com.h6.crm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.h6.crm.annotation.ResponseResult;
import com.h6.crm.service.ClientService;
import com.h6.crm.util.pojo.R;
import com.h6.crm.util.pojo.vo.QueryClientVO;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;

import com.h6.crm.entity.Client;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "客户管理", description = "客户管理的API")
@RestController
@RequestMapping("/client")
@ResponseResult
public class ClientController {

  @Autowired
  ClientService clientService;

  @Operation(summary = "查询有效的客户列表")
  @ApiResponses({
      @ApiResponse(responseCode = "200", content = {
          @Content(schema = @Schema(implementation = R.class), mediaType = "application/json") }) })
  @PostMapping("/list")
  public IPage<Client> queryClientList(@Valid @RequestBody QueryClientVO clientVo) {
    return clientService.queryClientList(clientVo);
  }

  @Operation(summary = "查询全部的客户列表")
  @ApiResponses({
      @ApiResponse(responseCode = "200", content = {
          @Content(schema = @Schema(implementation = R.class), mediaType = "application/json") }) })
  @PostMapping("/list/all")
  public IPage<Client> queryAllClientList(@Valid @RequestBody QueryClientVO clientVo) {
    return clientService.queryAllClientList(clientVo);
  }

  // @Operation(summary = "保存客户信息")
  // @ApiResponses({
  // @ApiResponse(responseCode = "200", content = {
  // @Content(schema = @Schema(implementation = R.class), mediaType =
  // "application/json") }) })
  // @PostMapping("/save")
  // public Boolean save(@Valid @RequestBody SaveClientVO clientVo,
  // @Parameter(hidden = true) @LoginUser SysUser user) {
  // return clientService.saveClient(clientVo, user);
  // }

  // @Operation(summary = "删除客户")
  // @ApiResponses({
  // @ApiResponse(responseCode = "200", content = {
  // @Content(schema = @Schema(implementation = R.class), mediaType =
  // "application/json") }) })
  // @DeleteMapping("/{clientId}")
  // public Boolean delete(@Parameter(description = "客户ID", required = true)
  // @PathVariable("clientId") Long clientId) {
  // return clientService.removeById(clientId);
  // }

  @Operation(summary = "查询客户详细信息")
  @ApiResponses({
      @ApiResponse(responseCode = "200", content = {
          @Content(schema = @Schema(implementation = R.class), mediaType = "application/json") }) })
  @PostMapping("/{clientId}")
  public Client getClientDetail(
      @Parameter(description = "客户ID", required = true) @PathVariable("clientId") Long clientId) {
    return clientService.getById(clientId);
  }

}
